
package com.shop.cloud.mall.api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.constant.SecurityConstants;
import com.shop.cloud.common.core.feign.entity.FeignPageParam;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.live.common.entity.LiveRoom;
import com.shop.cloud.live.common.feign.FeignLiveRoomService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 直播间商城用户端使用
 *
 * @author 
 * @date 2025-01-09 10:53:37
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/liveroom")
@Tag(description = "liveroom", name = "直播间")
public class LiveRoomController {

    private final FeignLiveRoomService feignLiveRoomService;

    /**
     * 直播间分页列表
     * @param page 分页对象
     * @param liveRoom 直播间
     * @return
     */
    @Operation(summary = "直播间分页列表")
    @GetMapping("/page")
    public R getPage(Page page, LiveRoom liveRoom) {
        FeignPageParam<LiveRoom> params = new FeignPageParam();
        params.setPage(page);
        params.setEtity(liveRoom);
        params.setOrders(page.orders());
        return feignLiveRoomService.getPage(params, SecurityConstants.FROM_IN);
    }

    /**
     * 直播间查询
     * @param id
     * @return R
     */
    @Operation(summary = "直播间查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") String id) {
        return feignLiveRoomService.getById(id, SecurityConstants.FROM_IN);
    }

    /**
     * 获取指定直播间播流地址
     * @param id
     * @param playType
     * @return
     */
    @Operation(summary = "获取指定直播间播流地址")
    @GetMapping("/pullurl/{id}/{playtype}")
    public R getPullUrl(@PathVariable("id") String id, @PathVariable("playtype") Integer playType) {
        return feignLiveRoomService.getPullUrl(id, playType, SecurityConstants.FROM_IN);
    }
}
